home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / ctlmod / treepr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-18  |  3.9 KB  |  230 lines

  1. # include    <ingres.h>
  2. # include    <symbol.h>
  3. # include    <tree.h>
  4. # include    <aux.h>
  5. # include    <sccs.h>
  6.  
  7. SCCSID(@(#)treepr.c    8.2    5/1/86)
  8.  
  9. /*
  10. **  TREEPR -- print tree for debugging
  11. **
  12. **    This routine prints a tree for debugging.
  13. **
  14. **    Parameters:
  15. **        tree -- root of tree to be printed
  16. **
  17. **    Returns:
  18. **        none
  19. **
  20. **    Side Effects:
  21. **        output to terminal
  22. */
  23.  
  24. static void rcsvtrpr();
  25.  
  26. void
  27. treepr(tree)
  28. QTREE    *tree;
  29. {
  30.     register QTREE    *t;
  31.     register int    i;
  32.  
  33.     t = tree;
  34.  
  35.     printf("Querytree @ %x:\n", t);
  36.  
  37.     /* print range table */
  38.     for (i = 0; i < MAXVAR + 1; i++)
  39.     {
  40.         if (Qt.qt_rangev[i].rngvdesc == NULL)
  41.             continue;
  42.         printf("range of %d is %.14s\n",
  43.             i, Qt.qt_rangev[i].rngvdesc->reldum.relid);
  44.     }
  45.  
  46.     /* print query type */
  47.     if (Qt.qt_qmode >= 0)
  48.         printf("Qmode %d ", Qt.qt_qmode);
  49.  
  50.     /* print result relation if realistic */
  51.     if (Qt.qt_resvar >= 0)
  52.         printf("resvar %d ", Qt.qt_resvar);
  53.     printf("\n");
  54.  
  55.     /* print tree */
  56.     rcsvtrpr(t);
  57.  
  58.     /* print exciting final stuff */
  59.     printf("\n");
  60. }
  61. /*
  62. **  RCSVTRPR -- traverse and print tree
  63. **
  64. **    This function does the real stuff for treepr.  It recursively
  65. **    traverses the tree in postfix order, printing each node.
  66. **
  67. **    Parameters:
  68. **        tree -- the root of the tree to print.
  69. **
  70. **    Returns:
  71. **        none
  72. **
  73. **    Side Effects:
  74. **        none
  75. **
  76. **    Trace Flags:
  77. **        none
  78. */
  79.  
  80. static
  81. void
  82. rcsvtrpr(tree)
  83. QTREE    *tree;
  84. {
  85.     register QTREE    *t;
  86.  
  87.     t = tree;
  88.  
  89.     while (t != NULL)
  90.     {
  91.         nodepr(t);
  92.         rcsvtrpr(t->left);
  93.         t = t->right;
  94.     }
  95. }
  96. /*
  97. **  NODEPR -- print tree node for debugging
  98. **
  99. **    Parameters:
  100. **        tree -- the node to print.
  101. **
  102. **    Returns:
  103. **        none
  104. **
  105. **    Side Effects:
  106. **        output to terminal
  107. */
  108.  
  109. nodepr(tree)
  110. QTREE    *tree;
  111. {
  112.     register QTREE    *t;
  113.     register int    ty;
  114.     int        l;
  115.     char        *cp;
  116.  
  117.     t = tree;
  118.     ty = t->sym.type;
  119.     l = t->sym.len & I1MASK;
  120.  
  121.     printf("%x: %x, %x/ ", t, t->left, t->right);
  122.     xputchar(ty);
  123.     printf("%d: ", l);
  124.  
  125.     switch (ty)
  126.     {
  127.       case VAR:
  128.         printf("%d.%d [", t->sym.value.sym_var.varno,
  129.             t->sym.value.sym_var.attno);
  130.         xputchar(t->sym.value.sym_var.varfrmt);
  131.         printf("%d]: %x", t->sym.value.sym_var.varfrml & I1MASK,
  132.                   t->sym.value.sym_var.valptr);
  133.         if (t->sym.value.sym_var.varno == -1)
  134.         {
  135.             printf("\n\tSub var: ");
  136.             if (t->sym.value.sym_var.valptr != NULL)
  137.                 nodepr((QTREE *) t->sym.value.sym_var.valptr);
  138.             else
  139.                 printf("ERROR: no value\n");
  140.             return;
  141.         }
  142.         else
  143.         {
  144.             if (t->sym.value.sym_var.valptr != NULL)
  145.             {
  146.                 printf(" = ");
  147.                 printatt(t->sym.value.sym_var.varfrmt,
  148.                      t->sym.value.sym_var.varfrml,
  149.                      t->sym.value.sym_var.valptr);
  150.             }
  151.         }
  152.         break;
  153.  
  154.       case RESDOM:
  155.         printf("%d [%c%d]", t->sym.value.sym_resdom.resno,
  156.             t->sym.value.sym_resdom.resfrmt,
  157.             t->sym.value.sym_resdom.resfrml);
  158.         break;
  159.  
  160.       case AOP:
  161.         printf("%d [%c%d] [%c%d]", t->sym.value.sym_op.opno,
  162.             t->sym.value.sym_op.opfrmt, t->sym.value.sym_op.opfrml,
  163.             t->sym.value.sym_op.agfrmt, t->sym.value.sym_op.agfrml);
  164.         break;
  165.  
  166.       case UOP:
  167.       case BOP:
  168.       case COP:
  169.       case INT:
  170.       case QMODE:
  171.       case RESULTVAR:
  172.         switch (t->sym.len)
  173.         {
  174.           case 1:
  175.           case 2:
  176.             printf("%d", t->sym.value.sym_data.i2type);
  177.             break;
  178.         
  179.           case 4:
  180.             printf("%ld", t->sym.value.sym_data.i4type);
  181.             break;
  182.         }
  183.         break;
  184.  
  185.       case FLOAT:
  186.         switch (t->sym.len)
  187.         {
  188.           case 4:
  189.             printf("%.10f", t->sym.value.sym_data.f4type);
  190.             break;
  191.  
  192.           case 8:
  193.             printf("%.10f", t->sym.value.sym_data.f8type);
  194.             break;
  195.         }
  196.         break;
  197.  
  198.       case CHAR:
  199.         cp = t->sym.value.sym_data.c0type;
  200.         while (l--)
  201.             xputchar(*cp++);
  202.         break;
  203.  
  204.       case AND:
  205.       case ROOT:
  206.       case AGHEAD:
  207.         printf("[%d/%d] [%o/%o]",
  208.             t->sym.value.sym_root.tvarc, t->sym.value.sym_root.lvarc,
  209.             t->sym.value.sym_root.lvarm, t->sym.value.sym_root.rvarm);
  210.         if (ty != AND)
  211.             printf(" (%d)", t->sym.value.sym_root.rootuser);
  212.         break;
  213.  
  214.       case TREE:
  215.       case OR:
  216.       case QLEND:
  217.       case BYHEAD:
  218.         break;
  219.  
  220.       case RESULTID:
  221.       case SOURCEID:
  222.         printf("%.14s", t->sym.value.sym_data.c0type);
  223.         break;
  224.  
  225.       default:
  226.         syserr("nodepr: ty %d", ty);
  227.     }
  228.     printf("/\n");
  229. }
  230.